package com.cmcc.pp.ui

import android.os.Bundle
import android.widget.EditText
import butterknife.Bind
import com.cmcc.pp.R
import com.cmcc.pp.api.ParamTools
import com.cmcc.pp.api.TestApi
import com.cmcc.pp.base.BActivity
import com.cmcc.pp.ui.widget.RefreshLinearLayout
import com.zrspring.libv2.network.Client
import com.zrspring.libv2.network.RxUtils
import com.zrspring.libv2.util.ToastUtils
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.fragment_transactiondate.*
import okhttp3.MediaType
import okhttp3.RequestBody

/**
 * Created by shopping on 2017/12/22 11:56.
 * https://github.com/wheroj
 */
class TestActivity : BActivity() {

    override fun getContentLayoutId(): Int {
        return R.layout.fragment_transactiondate
    }

    override fun getHasTitle(): Boolean {
        return true
    }

    override fun isSetStatusBarTransparent(): Boolean {
        return false
    }

    override fun initView(savedInstanceState: Bundle?) {
        header.setTitle("测试")
//        header.showLeftTextAndDrawable("返回", R.mipmap.icon_back)
        header.showLeftImage(R.mipmap.iocn_menubar)

//        replaceShow(TestFragment(), R.id.frameLayout)
    }

    override fun loadData() {
        val paramsTool = ParamTools()
        paramsTool.addParam("userId", "65")
        val requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), paramsTool.param)
        val testNet = Client.getApi<TestApi>(TestApi::class.java).testNet(requestBody)
//        var progressDlg = ProgressDlg(this, "登陆中......")
//        RxUtils.acquireString(testNet, httpListener = object : RxUtils.DefaultListener(progressDlg){
//            override fun onError(e: Throwable) {
//                super.onError(e)
//                showError("加载出错了，轻点屏幕重试一下呢")
//            }
//
//            override fun onResult(result: String) {
//                ToastUtils.show(result)
//            }
//        })

        RxUtils.acquireString(testNet, httpListener = object : RxUtils.HttpListener {
            override fun onError(e: Throwable) {
                content?.updateStatus(RefreshLinearLayout.FAIL)
            }

            override fun onComplete() {
                content?.updateStatus(RefreshLinearLayout.SUCCESS)
            }

            override fun onStart(d: Disposable) {
                content?.updateStatus(RefreshLinearLayout.LOADING)
            }

            override fun onResult(result: String) {
                ToastUtils.show(result)
            }
        })
    }
}